﻿<ctrl:GuiControl x:Class="CannedBytes.CommandLineGui.UI.Controls.GroupOptionsControl" x:ClassModifier="internal"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ctrl="clr-namespace:CannedBytes.CommandLineGui.UI.Controls"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"
             ToolTip="{Binding Description, Mode=OneTime}">

    <Grid Name="LayoutGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"  />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Name="GroupOptionsLabel" Content="{Binding Path=Name, Mode=OneTime}" Grid.ColumnSpan="2"/>
        <Button Name="Deselect" Grid.Column="3" Click="Deselect_Click" ToolTip="Deselect selected item.">
            <Image Source="/CannedBytes.CommandLineGui;component/Resources/Decrease.png" />
        </Button>

        <!-- ItemTemplateSelector="{StaticResource ControlTemplateSelector}" -->
        <ListBox Name="GroupOptionsList"
                 ItemsSource="{Binding Bindings}"
                 SelectedItem="{Binding SelectedOption, Mode=TwoWay}"
                 HorizontalContentAlignment="Stretch"
                 SelectionChanged="GroupOptionsList_SelectionChanged"
                 Grid.Row="1" Grid.ColumnSpan="3" Grid.IsSharedSizeScope="True" >

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition SharedSizeGroup="GroupOptionCol1" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <RadioButton IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=IsSelected}" />

                        <ContentPresenter Content="{Binding}" ContentTemplateSelector="{StaticResource ControlTemplateSelector}"
                                        HorizontalAlignment="Stretch"
                                        Grid.Column="1" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</ctrl:GuiControl>